package com.gm;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Administrator on 13-12-21.
 */
public class ButtonFrame extends GCommonFrame {
    public ButtonFrame() throws HeadlessException {
        setTitle("Color Frame");



//        JButton blueBtn=new JButton("Blue");
//        JButton redBtn=new JButton("Red");
//        JButton yellowBtn=new JButton("Yellow");

        button_panel=new JPanel();
//        blueBtn.addActionListener(new ColorActionListener(Color.blue));
//        button_panel.add(blueBtn);
//        redBtn.addActionListener(new ColorActionListener(Color.red));
//        button_panel.add(redBtn);
//        yellowBtn.addActionListener(new ColorActionListener(Color.yellow));
//        button_panel.add(yellowBtn);

        makeButton("Blue",Color.blue);
        makeButton("Red",Color.red);
        makeButton("Yellow",Color.yellow);
        add(button_panel);

        UiPanel up=new UiPanel(this);
        add(up,BorderLayout.SOUTH);

    }

    public void makeButton(String title,final Color c){
        JButton btn=new JButton(title);
        button_panel.add(btn);

        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                button_panel.setBackground(c);
            }
        });
    }
    private class ColorActionListener implements ActionListener{
        private ColorActionListener(Color c) {
            this.color=c;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            button_panel.setBackground(this.color);
        }



        private Color color;
    }
    private JPanel button_panel;



}
